package com.jic.member.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.member.entity.MememberIntegralExchangeCoupon;
import com.jic.member.mapper.MememberIntegralExchangeCouponMapper;
import com.jic.member.service.MememberIntegralExchangeCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员积分规则兑换优惠券红包表
 * @author : 
 * @email : 
 * @since : 2020-04-02 03:30:16
 * @version : v1.0.0
 */
@Service
public class MememberIntegralExchangeCouponServiceImpl implements MememberIntegralExchangeCouponService {

    @Autowired
    private MememberIntegralExchangeCouponMapper mememberIntegralExchangeCouponMapper;

    @Override
    public long insert(MememberIntegralExchangeCoupon mememberIntegralExchangeCoupon) {
        long flag = mememberIntegralExchangeCouponMapper.insert(mememberIntegralExchangeCoupon);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return mememberIntegralExchangeCouponMapper.delete(id);
    }

    @Override
    public long update(MememberIntegralExchangeCoupon mememberIntegralExchangeCoupon) {
        return mememberIntegralExchangeCouponMapper.update(mememberIntegralExchangeCoupon);
    }

    @Override
    public MememberIntegralExchangeCoupon queryByPrimaryKey(Long id){
        return mememberIntegralExchangeCouponMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MememberIntegralExchangeCoupon> query(MememberIntegralExchangeCoupon mememberIntegralExchangeCoupon){
        return mememberIntegralExchangeCouponMapper.query(mememberIntegralExchangeCoupon);
    }

    @Override
    public PageResult<MememberIntegralExchangeCoupon> queryPage(MememberIntegralExchangeCoupon mememberIntegralExchangeCoupon, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MememberIntegralExchangeCoupon> list = mememberIntegralExchangeCouponMapper.queryPage(startIndex, pageQuery.getLimit(), mememberIntegralExchangeCoupon);
        long count = mememberIntegralExchangeCouponMapper.queryPageCount(mememberIntegralExchangeCoupon);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}